<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="投资人" prop="createBy">
        <el-input
          v-model="queryParams.createBy"
          placeholder="请输入投资人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="approvalList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="股票代码" align="center" prop="stockCode" />
      <el-table-column label="股票名称" align="center" prop="stockName" />
      <el-table-column label="投资人" align="center" prop="createBy" />
      <el-table-column label="投资人综合评价" align="center" prop="feedbackEvaluate" :formatter="feedbackEvaluateFormat" />
      <el-table-column label="评价时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改反馈审核对话框 -->
    <el-dialog :visible.sync="open" append-to-body title="评价信息" width="800px">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-descriptions :column="1" title="股票评价详细信息">
          <el-descriptions-item label="股票代码">{{ form.stockCode }}</el-descriptions-item>
          <el-descriptions-item label="股票名称">{{ form.stockName }}</el-descriptions-item>
          <el-descriptions-item label="当前股票价值">{{ form.latestPrice }}</el-descriptions-item>
          <el-descriptions-item label="分红状态评价">{{feedbackDividendFormat(form) }}</el-descriptions-item>
          <el-descriptions-item label="资金使用情况评价">{{ feedbackMoneytrackFormat(form) }}</el-descriptions-item>
          <el-descriptions-item label="综合反馈评价">{{ feedbackEvaluateFormat(form) }}</el-descriptions-item>
          <el-descriptions-item label="评价时间">{{ form.createTime }}</el-descriptions-item>
          <el-descriptions-item label="审核时间">{{ form.updateTime }}</el-descriptions-item>
          <el-descriptions-item label="详细评价">{{ form.feedbackMessage }}</el-descriptions-item>
        </el-descriptions>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {getApproval, delApproval,myListApproval,updateApproval } from "@/api/operate/feedback/approval";
  import { listStock, getStock, updateStock} from "@/api/operate/stock";
  export default {
    name: "Approval",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 反馈审核表格数据
        approvalList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 发行人分红状态字典
        feedbackDividendOptions: [],
        // 发行人资金使用情况字典
        feedbackMoneytrackOptions: [],
        // 发行人反馈评价字典
        feedbackEvaluateOptions: [],
        // 审核状态字典
        feedbackVerifyOptions: [],
        radioTreaty: '1',
        btnstatus:true,
        treaty: null,
        //股票对象
        mystrock: null,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          stockCode: null,
          stockName: null,
          stockOwnerid: null,
          stockOwnername: null,
          feedbackDividend: null,
          feedbackMoneytrack: null,
          feedbackEvaluate: null,
          feedbackMessage: null,
          feedbackVerify: 1,
          deptId: null,
          createById: null,
          updateById: null,
          treaty: null,
          latestPrice: 0,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          feedbackVerify: [
            { required: true, message: "审核状态不能为空", trigger: "change" }
          ],
        }
      };
    },
    created() {
      this.getList();
      this.getDicts("feedback_dividend").then(response => {
        this.feedbackDividendOptions = response.data;
      });
      this.getDicts("feedback_moneytrack").then(response => {
        this.feedbackMoneytrackOptions = response.data;
      });
      this.getDicts("feedback_evaluate").then(response => {
        this.feedbackEvaluateOptions = response.data;
      });
      this.getDicts("feedback_verify").then(response => {
        this.feedbackVerifyOptions = response.data;
      });
    },
    methods: {
      /** 查询反馈审核列表 */
      getList() {
        this.loading = true;
        myListApproval(this.queryParams).then(response => {
          this.approvalList = response.rows;
          this.total = response.total;
          this.loading = false;
        });

      },
      // 发行人分红状态字典翻译
      feedbackDividendFormat(row, column) {
        return this.selectDictLabel(this.feedbackDividendOptions, row.feedbackDividend);
      },
      // 发行人资金使用情况字典翻译
      feedbackMoneytrackFormat(row, column) {
        return this.selectDictLabel(this.feedbackMoneytrackOptions, row.feedbackMoneytrack);
      },
      // 发行人反馈评价字典翻译
      feedbackEvaluateFormat(row, column) {
        return this.selectDictLabel(this.feedbackEvaluateOptions, row.feedbackEvaluate);
      },
      // 审核状态字典翻译
      feedbackVerifyFormat(row, column) {
        return this.selectDictLabel(this.feedbackVerifyOptions, row.feedbackVerify);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          stockCode: null,
          stockName: null,
          stockOwnerid: null,
          stockOwnername: null,
          feedbackDividend: 0,
          feedbackMoneytrack: 0,
          feedbackEvaluate: 0,
          feedbackMessage: null,
          feedbackVerify: 1,
          deptId: null,
          createBy: null,
          createById: null,
          createTime: null,
          updateBy: null,
          updateById: null,
          updateTime: null,
          remark: null,
          latestPrice: 0,
          treaty: null,
          mystrock: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加反馈审核";
      },
      /** 审核按钮操作 */
      async handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        let detail = await getApproval(id);
        if (detail && detail.code === 200) {
          this.form = detail.data;
          let stockdetail = await listStock({
            code: detail.stockCode
          });

          if (stockdetail && stockdetail.code === 200 && stockdetail.total > 0) {
            this.form.latestPrice = stockdetail.rows[0].latestPrice;
            this.mystrock = stockdetail.rows[0];
            console.log(this.mystrock)
          }
        }
        this.open = true;
        this.title = "进行审核";
      },
    }
  };

</script>

<style scoped>
  .box-card {
    margin: 20px 0;
  }

  .el-descriptions-title {
    margin-top: 40px;
    margin-bottom: 20px;
    font-size: 16px;
    font-weight: bold;
  }

  .margin-top {
    margin-top: 20px;
  }
</style>
